<?php

namespace app\modules\api\controllers;
//use yii\filters\auth\HttpBasicAuth;
use yii\rest\ActiveController;
use yii;
use yii\web\response;
use yii\base\Object;
use app\models\LoginForm;

class UserController extends ActiveController
{
    public $modelClass = 'app\models\Admin';
    
    public function behaviors()
    {
        $behaviors = parent::behaviors();
       /*  $behaviors['authenticator'] = [
            'class' => HttpBasicAuth::className(),
        ]; */
        $behaviors['contentNegotiator']['formats'] = '';
        $behaviors['contentNegotiator']['formats']['application/json'] = Response::FORMAT_JSON;
        return $behaviors;
    } 
    
    public function actions()
    {
        $actions = parent::actions();
        
        // 禁用"delete" 和 "create" 操作
        unset($actions['delete'], $actions['create'],$actions['index']);
        
        return $actions;
    }
    
    public function actionDologin()
    {
         $model = new LoginForm();
        
        $model->username = 'admin';
        
        $model->password = 'admin';
        
       if($model->login())
       {
           return array('1'=>'success');
       }else
       {
           return array('1'=>'fail');
       } 
        
       // return array('1'=>'fail');
    }
    
    public function actionTest()
    {
       // var_dump(\Yii::$app->user->isGuest);
        
        $request = \Yii::$app->request;
               
        $id = $request->get('id');
        
        if(!empty($id))
        {
            $id = $_GET['id'];            
            return array('1'=>$id);
        }else
        {        
            return array('1'=>'124');
        }
    }
}
